/*
 * Copyright (C) 2012 yueyueniao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.wzm.moviepic.fragment;



import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;


import com.wzm.moviepic.R;
import com.wzm.moviepic.slidingmenu.Main1Activity;



public class AboutFragment extends Fragment {
	
	private WebView yjWeb = null;
	private ImageView btn_back = null;
	private ImageView btn_neterror = null;
	
	private TextView tv1,tv2;
	
	//手势
	private GestureDetector detector;
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_about, null);
		tv1 = (TextView)view.findViewById(R.id.tv_wtitle);
		tv2 = (TextView)view.findViewById(R.id.tv_wtitle1);
		Bundle db = getArguments();
		final int actionid = db.getInt("key");
		yjWeb = (WebView)view.findViewById(R.id.webView1);
		WebSettings webSettings = yjWeb.getSettings();
		webSettings.setJavaScriptEnabled(true);
		
		btn_neterror = (ImageView)view.findViewById(R.id.img_neterror);
		
		yjWeb.setVisibility(View.VISIBLE);
		
		btn_back = (ImageView)view.findViewById(R.id.btn_imgback);
		btn_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();	
				SystemFragment page2 = new SystemFragment();
				
				t.replace(R.id.left_frame, page2);
				t.commit();
				page2 = null;
			}
		});
		
		
//		if(NetworkUtils.getNetworkState(getActivity())== NetworkUtils.NETWORN_NONE)
//		{
//			yjWeb.setVisibility(View.GONE);
//			btn_neterror.setVisibility(View.VISIBLE);
//			btn_neterror.setOnClickListener(new OnClickListener() {
//				
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					if(NetworkUtils.getNetworkState(getActivity())== NetworkUtils.NETWORN_NONE)
//					{
//						Toast.makeText(getActivity(), "还是没有网络哦", Toast.LENGTH_SHORT).show();
//						
//					}else{
//						yjWeb.setVisibility(View.VISIBLE);
//						btn_neterror.setVisibility(View.GONE);
//						yjWeb.setBackgroundColor(0);
//						switch(actionid)
//						{
//						case 0://已经及反馈
//							tv1.setText("意见反馈");
//							tv2.setText("您的支持是我们最大的动力");
//							yjWeb.loadUrl("http://www.gaoqing.mobi/BackStage2/problem.html");
//							break;
//						case 1://关于
//							tv1.setText("关于我们");
//							tv2.setText("应用详情和免责声明");
//							yjWeb.loadUrl("http://www.gaoqing.mobi/BackStage2/aboutus.html");
//							break;
//						}
//					}
//				}
//			});
//			
//			return view;
//		}
		
		yjWeb.setBackgroundColor(0);
		switch(actionid)
		{
		case 0://已经及反馈
			tv1.setText("意见反馈");
			tv2.setText("您的支持是我们最大的动力");
			yjWeb.loadUrl("http://www.gaoqing.mobi/BackStage2/problem.html");
			break;
		case 1://关于
			tv1.setText("关于我们");
			tv2.setText("应用详情和免责声明");
			yjWeb.loadUrl("http://www.gaoqing.mobi/BackStage2/aboutus.html");
			break;
		}
		
		
		detector = new GestureDetector(getActivity(),new OnGestureListener() {
			
			@Override
			public boolean onSingleTapUp(MotionEvent e) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public void onShowPress(MotionEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
					float distanceY) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public void onLongPress(MotionEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
					float velocityY) {
				// TODO Auto-generated method stub
				
				if (e1.getX() - e2.getX() > 120) {
					//Logger.info("向左...");
					((Main1Activity)getActivity()).showcenter();
		            return true;
		        } else if (e1.getX() - e2.getX() < -120) {
		        	{//本地资源页面
		        		FragmentTransaction t = getActivity().getSupportFragmentManager()
								.beginTransaction();
						t.setCustomAnimations(R.anim.push_right_in, R.anim.push_right_out);
						SystemFragment page2 = new SystemFragment();
						t.replace(R.id.left_frame, page2);
						t.commit();
						page2 = null;
		        	}
		            return true;
		        }
				
				return false;
			}
			
			@Override
			public boolean onDown(MotionEvent e) {
				// TODO Auto-generated method stub
				return false;
			}
		});
		yjWeb.setOnTouchListener(new OnTouchListener() {
		
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				return detector.onTouchEvent(event);
			}
		});
		
		
		
		
		return view;
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	
}
